package com.egao.customer.controller;

import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.customer.entity.PayHistory;
import com.egao.customer.service.PayHistoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;


/**
 *
 * 缴费记录
 * @author : Doman
 * @date : 2020-06-14 21:03:22
 * @version ：1.0
 */

@Controller
@RequestMapping("/customer/payHistory")
public class PayHistoryController extends BaseController {

	@Autowired
	private PayHistoryService payHistoryService;

  /**
   * 页面
   **/
  @RequiresPermissions("customer:payHistory:view")
  @RequestMapping()
  public String view() {
    return "customer/payHistory.html";
  }

	/**
	 * 页面
	 **/
	@RequiresPermissions("customer:payHistory:view")
	@RequestMapping("/payHistorySummaryJf")
	public String payHistorySummaryJf() {
		return "customer/payHistorySummaryJf.html";
	}

	/**
	 * 页面
	 **/
	@RequiresPermissions("customer:payHistory:view")
	@RequestMapping("/payHistorySummaryYfk")
	public String payHistorySummaryYfk() {
		return "customer/payHistorySummaryYfk.html";
	}

	/**
	 * 分页查询列表
	 */
	@RequiresPermissions("customer:payHistory:list")
	@OperLog(value = "缴费记录", desc = "分页查询")
	@ResponseBody
	@RequestMapping("/listSummaryJf")
    public JSONObject listSummaryJf(PageResult2<T> page, PayHistory payHistory) throws Exception{
        return payHistoryService.listSummaryJf(page, payHistory);
    }

	/**
	 * 分页查询列表
	 */
	@RequiresPermissions("customer:payHistory:list")
	@OperLog(value = "缴费记录", desc = "分页查询")
	@ResponseBody
	@RequestMapping("/listSummaryYfk")
    public JSONObject listSummaryYfk(PageResult2<T> page, PayHistory payHistory) throws Exception{
        return payHistoryService.listSummaryYfk(page, payHistory);
    }

	/**
	 * 分页查询列表
	 */
	@RequiresPermissions("customer:payHistory:list")
	@OperLog(value = "缴费记录", desc = "分页查询")
	@ResponseBody
	@RequestMapping("/page")
    public JSONObject list(PageResult2<T> page, PayHistory payHistory) throws Exception{
        return payHistoryService.list(page, payHistory, getLoginUser());
    }

    /**
     * 查询全部缴费记录
     */
    @RequiresPermissions("customer:payHistory:list")
    @OperLog(value = "缴费记录", desc = "查询全部")
    @ResponseBody
    @RequestMapping("/list")
    public String list(PayHistory payHistory){
        return JSONArray.fromObject(payHistoryService.list(payHistory, getLoginUser())).toString();
    }

    /**
     * 根据id查询缴费记录
     */
    @RequiresPermissions("customer:payHistory:list")
    @OperLog(value = "缴费记录", desc = "根据id查询")
    @ResponseBody
    @RequestMapping("/get")
    public JsonResult get(PayHistory payHistory) {
        return JsonResult.ok().setData(payHistoryService.getById(payHistory));
		// 使用关联查询
        //PageParam<payHistory> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<payHistory> records = payHistoryService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加缴费记录
     */
    @RequiresPermissions("customer:payHistory:save")
    @OperLog(value = "缴费记录", desc = "添加", param = false, result = true)
    @ResponseBody
    @RequestMapping("/save")
    public JsonResult save(Model model, PayHistory payHistory) {
        return payHistoryService.save(payHistory, getLoginUser());
    }

    /**
     * 添加缴费记录
     */
    @RequiresPermissions("customer:payHistory:save")
    @OperLog(value = "缴费记录违规", desc = "添加", param = false, result = true)
    @ResponseBody
    @RequestMapping("/saveWg")
    public JsonResult saveWg(Model model, PayHistory payHistory) {
        return payHistoryService.saveWg(payHistory, getLoginUser());
    }

    /**
     * 修改缴费记录
     */
    @RequiresPermissions("customer:payHistory:update")
    @OperLog(value = "缴费记录", desc = "修改", param = false, result = true)
    @ResponseBody
    @RequestMapping("/update")
    public JsonResult update(Model model, PayHistory payHistory) {
        return payHistoryService.update(payHistory, getLoginUser());
    }

    /**
     * 修改缴费记录
     */
    @RequiresPermissions("customer:payHistory:update")
    @OperLog(value = "缴费记录", desc = "修改", param = false, result = true)
    @ResponseBody
    @RequestMapping("/updateWg")
    public JsonResult updateWg(Model model, PayHistory payHistory) {
        return payHistoryService.updateWg(payHistory, getLoginUser());
    }

    /**
     * 删除缴费记录
     */
    @RequiresPermissions("customer:payHistory:remove")
    @OperLog(value = "缴费记录", desc = "删除", result = true)
    @ResponseBody
    @RequestMapping("/remove")
    public JsonResult remove(PayHistory payHistory ) {
        return payHistoryService.remove(payHistory, getLoginUser());
    }

    /**
     * 批量添加缴费记录
     */
    /**@RequiresPermissions("customer:payHistory:save")
    @OperLog(value = "缴费记录", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @RequestMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<PayHistory> list) {
        if (payHistoryService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改缴费记录
     */
    /**@RequiresPermissions("customer:payHistory:update")
    @OperLog(value = "缴费记录", desc = "批量修改", result = true)
    @ResponseBody
    @RequestMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<PayHistory> batchParam) {
        if (batchParam.update(payHistoryService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除缴费记录
     */
    /**@RequiresPermissions("customer:payHistory:remove")
    @OperLog(value = "缴费记录", desc = "批量删除", result = true)
    @ResponseBody
    @RequestMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (payHistoryService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
